/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package clinivida.DAO;

import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
import javax.persistence.Persistence;




public class ConexaoSingleton {
    private EntityManager conn;
    private static ConexaoSingleton me;
    private EntityManagerFactory emf;

    private ConexaoSingleton(){
        emf = Persistence.createEntityManagerFactory("CliniVida");
        conn = emf.createEntityManager();
    }


    public EntityManager getEntityManager(){
        return conn = emf.createEntityManager();
    }
    
     public static EntityManager getConexao() throws DaoException {
    try{
        if(me == null){
            me = new ConexaoSingleton();
        }
    }catch(Exception ex){
        //throw new DaoException(DaoException.TIPO__ERRO_CONEXAO_BANCO_DADOS);
        ex.printStackTrace();
    }
    return me.getEntityManager();
    }
}


